<?php

class Db_PaymentLog
{
    public static $payment_status = array(
        0 => 'Chưa thanh toán',
        1 => '<font color="green">Thành công</font>',
        2 => '<font color="red">Hủy</font>'
    );

    public static $payment_type = array(
        0 => 'Chưa xác định',
        1 => 'Quốc tế',
        2 => 'Nội địa',
        7 => 'Chuyển khoản'
    );

    public static function getPaymentLogByCartId($order_id, $call_pos='') {
        return DB::fetch("SELECT * FROM payment_log WHERE order_id= $order_id", false, false, $call_pos);
    }

    public static function log($data=array()) {
        $data['user_id'] = User::id();
        $data['user_email'] = User::user_email();
        $data['created_time'] = TIME_NOW;
        return DB::insert('payment_log', $data, false,  __FILE__ . ' line ' . __LINE__);
    }

    public static function update($id, $data) {
        return DB::update_id('payment_log', $data, $id);
    }

    public static function insertToQueue($order_id){
        if(REDIS_ON == 1){
            $redis = RedisPhp::getInstance('payment_log');
            $redis->sAdd('payment_log', $order_id);
        }
    }

    public static function removeFromQueue($order_id){
        if(REDIS_ON == 1){
            $redis = RedisPhp::getInstance('payment_log');
            $redis->sRemove('payment_log', $order_id);
        }
    }

    public static function getQueue(){
        if(REDIS_ON == 1){
            $redis = RedisPhp::getInstance('payment_log');
            return $redis->sMembers('payment_log');
        }
    }

    public static function deleteQueue(){
        if(REDIS_ON == 1){
            $redis = RedisPhp::getInstance('payment_log');
            return $redis->delete('payment_log');
        }
    }
}